package com.project_doctor.controller;

import com.project_doctor.exception.SystemCode;
import com.project_doctor.pojo.AnnouncementReceiver;
import com.project_doctor.pojo.Team;
import com.project_doctor.service.AnnouncementReceiverService;
import com.project_doctor.service.TeamService;
import com.project_doctor.util.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("annReceiver")
public class AnnReceiverController {
    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    AnnouncementReceiverService announcementReceiverService;
    //注入Rabbit模板类
    @Autowired
    private RabbitTemplate rabbitTemplate;


    @PostMapping("/listForAnnReceiver/{id}")
    public ResponseEntity<?> listForAnnReceiver(@PathVariable Long id) {
        List<AnnouncementReceiver> list = announcementReceiverService.listForAnnReceiver(id);
        return ResponseEntity.ok(list);
    }

    @PutMapping("/markAsRead")
    public ResponseEntity<?> markAsRead(@RequestBody Map<String, Long> map) {
        Long announcementId = map.get("announcementId");
        Long receiverId = map.get("receiverId");
        announcementReceiverService.markAsRead(announcementId, receiverId);
        return ResponseEntity.ok(SystemCode.SUCCESS_MARKASREAD_ANNOUNCEMENT.getMessage());
    }
    @DeleteMapping("deleteAnnReceiver/{announcementId}/{receiverId}")
    public ResponseEntity<?> deleteAnnReceiver(@PathVariable Long announcementId, @PathVariable Long receiverId) {
        announcementReceiverService.deleteAnnReceiver(announcementId,receiverId);
        return ResponseEntity.ok(SystemCode.SUCCESS.getMessage());
    }
}
